//
//  findpasswordfirstViewController.m
//  BAOASystem
//
//  Created by michael on 2018/2/6.
//  Copyright © 2018年 czd. All rights reserved.
//
#import "findpasswordemailViewController.h"
#import "findpasswordtextViewController.h"
#import "findpasswordViewController.h"
#import "findpasswordfirstViewController.h"
#import "OALoginViewController.h"
@interface findpasswordfirstViewController ()

@end

@implementation findpasswordfirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:

[UIColor whiteColor],NSForegroundColorAttributeName, nil];
 
[self.navigationController.navigationBar setTitleTextAttributes:attributes];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"0a62ea"];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

    self.title = NSLocalizedString(@"找回密码", nil);
  UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回"]style:UIBarButtonItemStylePlain target:self action:@selector(buttonClick)];
 self.navigationItem.leftBarButtonItem = item1;
    self.view.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
        [self initview];

    // Do any additional setup after loading the view.
}
- (void)initview{
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, KScreenWidth-20, 20)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor colorWithHexString:@"484848"];
label.text =NSLocalizedString(@"请输入登录名", nil);
[self.view addSubview:label];
_textfield = [[UITextField alloc]initWithFrame:CGRectMake(10, label.bottom+10, KScreenWidth-20, 40)];
_textfield.backgroundColor = [UIColor whiteColor];

[self.view addSubview:_textfield];
  UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
      button2.frame = CGRectMake(10, _textfield.bottom+10, KScreenWidth-20, 40);
          button2.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

//        [button2.layer setBorderColor:[UIColor blueColor].CGColor];
//    [button2.layer setBorderWidth:1];
// [button2.layer setMasksToBounds:YES];
    [button2 setTitle:NSLocalizedString(@"注册信息-下一步", nil) forState:UIControlStateNormal];
    button2.titleLabel.font = [UIFont systemFontOfSize: 14.0];
          [button2 setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
//        button2.layer.cornerRadius = button.height/2;
                [button2 addTarget:self action:@selector(action2) forControlEvents:UIControlEventTouchUpInside];

            [self.view addSubview:button2];
}
- (void)action2{
NSString *phonestring=[_textfield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  NSString *name = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
     NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];
     NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
if ([phonestring isEqualToString:@""]|| phonestring.length == 0) {
        [self.view makeToast:NSLocalizedString(@"请输入登录名", nil)];
}else{
NSString *bodyStr = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>administrator</userName><password>b628e2c3b78ef9bf269c489b35176e48</password><website>%@</website><language>%@</language><type>%@</type></header><body><user><username>%@</username></user></body></message>",website,language,BAtype,phonestring];
    bodyStr= [bodyStr URLEncodedString];

 NSArray * array = @[@{@"arg0":bodyStr}];
     NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bcheckUserName];

 [HttpTools requestWithURL:path arrays:array method:@"checkUserName" success:^(id JSON) {
    [MBProgressHUD hideHUDForView:self.view animated:YES];
NSLog(@"%@",JSON);
[self.view makeToast:JSON[@"msg"]];
if ([[NSString stringWithFormat:@"%@",JSON[@"code"]]isEqualToString:@"200"])
{
  [[NSUserDefaults standardUserDefaults] setObject:phonestring forKey:@"userName"];

if ([_type isEqualToString:@"email"]) {
findpasswordemailViewController *vc = [[findpasswordemailViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];

}else{
findpasswordtextViewController *vc = [[findpasswordtextViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];

}

}
    } failure:^(NSError *error) {
      [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
    
}

//findpasswordViewController *vc = [[findpasswordViewController alloc]init];
//    [self.navigationController pushViewController:vc animated:YES];



}





- (void)buttonClick{

      UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

        OALoginViewController * loginVC = [storyBoard instantiateViewControllerWithIdentifier:@"LoginVC"];
        UINavigationController * navVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
    self.view.window.rootViewController = navVC;
        loginVC.navigationController.navigationBar.hidden = YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
